<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="manageProducts" binding="#{productManagerBean.loadManageProducts}">
                    <p:panel header="Products" id="productsPanel">
                        <p:messages />

                        <p:dataTable id="products" var="product" value="#{productManagerBean.products}" selectionMode="single" 
                                     selection="#{productManagerBean.selectedProduct}" update="productsPanel"  paginator="true" rows="10"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >
                            <p:column filterBy="#{product.code}" headerText="Code" filterMatchMode="contains">  
                                <h:outputText value="#{product.code}" />  
                            </p:column> 
                            <p:column filterBy="#{product.name}" headerText="Name" filterMatchMode="contains">  
                                <h:outputText value="#{product.name}" />  
                            </p:column> 
                            <p:column filterBy="#{product.description}" headerText="Description" filterMatchMode="contains">  
                                <h:outputText value="#{product.description}" />  
                            </p:column>
                            <p:column headerText="Price">  
                                <h:outputText value="#{product.price}" >
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Weight">  
                                <h:outputText value="#{product.weight}">
                                    <f:convertNumber minFractionDigits="2" />
                                </h:outputText>
                            </p:column> 
                            <p:column filterBy="#{product.capacityPerHour}" headerText="Capacity per Hour" filterMatchMode="contains">  
                                <h:outputText value="#{product.capacityPerHour}" />  
                            </p:column> 
                            <p:column filterBy="#{product.status}" headerText="Status" filterMatchMode="contains">  
                                <h:outputText value="#{product.status}" />  
                            </p:column> 
                        </p:dataTable>
                        <table class="table-submit">
                            <tr>
                                <td align="center">
                                    <p:commandButton id="btnAddAProduct" value="Add a Product" 
                                                     title="Add a product." ajax="true"
                                                     actionListener="#{productManagerBean.addProduct}" />
                                    &nbsp;&nbsp;&nbsp;
                                    <p:commandButton id="btnUpdateAProduct" value="Update Product" 
                                                     title="Update selected product." ajax="true"
                                                     update="productsPanel"
                                                     actionListener="#{productManagerBean.updateProduct}" />
                                    &nbsp;&nbsp;&nbsp;
                                    <p:commandButton id="btnRemoveProduct" value="Remove Product" 
                                                     onclick="confirmation.show()" type="button"
                                                     title="Remove the selected product." />
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:confirmDialog  width="400" message="" header="Removing a product" severity="alert" widgetVar="confirmation">
                        <f:facet name="message">
                            <h:outputText value="You are going to remove a product."/><br/>
                            <h:outputText value="Are you sure you want to continue?"/>
                        </f:facet>    
                        <table width="100%">
                            <tr>
                                <td align="center">
                                    <p:commandButton value="Yes" update="productsPanel" onclick="confirmation.hide()"
                                         actionListener="#{productManagerBean.removeProduct}"/>
                                    &nbsp;&nbsp;&nbsp;
                        <p:commandButton value="No" update="productsPanel" onclick="confirmation.hide()" type="button" />
                                </td>
                            </tr>
                        </table>
                        
                    </p:confirmDialog>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
